package com.ghost.view.UI
{
	import com.ghost.interfaces.Ibaseui;
	import com.ghost.manager.Tip_manager;
	import com.ghost.model.Global_data;
	import com.ghost.model.Object_pool;
	import com.ghost.view.Base_effect;
	
	import flash.display.Bitmap;
	import flash.events.Event;
	import flash.geom.PerspectiveProjection;

	public class Bottom_exp extends Base_effect implements Ibaseui
	{
		public var exp_current_num:int=100;//当前经验值
		public var exp_total_num:int=1000;//当前总经验值
		private var percent_exp:int=0;//当前经验百分比*100
		
		private var bg_b:Bitmap;
		private var left_b:Bitmap;
		private var view_b:Bitmap;
		private var right_b:Bitmap;
		public function Bottom_exp()
		{
			bg_b = new Bitmap(Object_pool.loaded_obj_pool.get("bottom_exp_ui").get("experience_bg"));
			left_b = new Bitmap(Object_pool.loaded_obj_pool.get("bottom_exp_ui").get("experience_left"));
			view_b = new Bitmap(Object_pool.loaded_obj_pool.get("bottom_exp_ui").get("experience_view"));
			right_b = new Bitmap(Object_pool.loaded_obj_pool.get("bottom_exp_ui").get("experience_right"));
			this.addChild(bg_b);
			this.addChild(view_b);
			this.addChild(left_b);
			this.addChild(right_b);
			view_b.x = bg_b.x = left_b.width;
			bg_b.y = (left_b.height-bg_b.height)/2;
			view_b.y = (left_b.height-view_b.height)/2;
			percent_exp = Math.floor(exp_current_num/exp_total_num*100);
			change_w();
			Tip_manager.getInstance().add_tip(this,"bottom_exp","经验值:"+String(exp_current_num)+"/"+String(exp_total_num)+"("+String(percent_exp)+"%)");
			//this.addEventListener("exp_change",change_Handler);
		}
		/**
		 * 经验值发生改变
		 */		
		public function change_Handler(e:*=null):void
		{
			percent_exp = Math.floor(exp_current_num/exp_total_num*100);
			view_b.width = int(percent_exp/100*bg_b.width);
			Object_pool.tip_obj_pool.get(this).change_content("","经验值:"+String(exp_current_num)+"/"+String(exp_total_num)+"("+String(percent_exp)+"%)");
		}
		/**
		 * 改变舞台情况下改变宽
		 */		
		public function change_w():void
		{
			bg_b.width = Global_data.stage_s_width-left_b.width-right_b.width;
			right_b.x = bg_b.width+bg_b.x;
			view_b.width = int(percent_exp/100*bg_b.width);
		}
		public function hide():void
		{
			this.visible = false;
		}
		public function show():void
		{
			this.visible = true;
		}
		public function reflash_x_y(e:*):void
		{
			change_w();
			this.x = Global_data.stage_s_width-this.width;
			this.y = Global_data.stage_s_height-this.height;
		}
	}
}